package com.winderinfo.yikaotianxia.ui.mockexam;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.core.utils.MapUtil;

import java.util.List;

public class MultipleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<AnswerBean.RowsBean> list;

    public MultipleAdapter(Context context, List<AnswerBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_ti, viewGroup, false);
        SelectedViewHolder selectedViewHolder = new SelectedViewHolder(view);
        return selectedViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
        SelectedViewHolder selectedViewHolder = (SelectedViewHolder) viewHolder;
        int id = list.get(i).getId();
        CardBean cardBean = MapUtil.cardBeanMap.get(id + "");
        if (cardBean != null) {
            if (!cardBean.getComplete().equals("0")) {
                selectedViewHolder.ii_b.setVisibility(View.VISIBLE);
                selectedViewHolder.ii_b.setText((i + 1) + "");
            } else {
                selectedViewHolder.ii_a.setVisibility(View.VISIBLE);
                selectedViewHolder.ii_a.setText((i + 1) + "");
            }
        } else {
            selectedViewHolder.ii_a.setVisibility(View.VISIBLE);
            selectedViewHolder.ii_a.setText((i + 1) + "");
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SelectedViewHolder extends RecyclerView.ViewHolder {

        private final TextView ii_a, ii_b;

        public SelectedViewHolder(@NonNull View itemView) {
            super(itemView);
            ii_a = itemView.findViewById(R.id.ii_a);
            ii_b = itemView.findViewById(R.id.ii_b);
        }
    }

    //接口回调
    public interface OnTiId {
        void getId(int id);
    }

    public OnTiId onTiId;

    public void setOnTiId(OnTiId onTiId) {
        this.onTiId = onTiId;
    }

}
